<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Session;
use app\index\model\mydb;
use think\Log;

class Dc extends Controller
{
	public function __construct(){
        parent::__construct();
        header("Access-Control-Allow-Origin", "*");
        header("Access-Control-Allow-Credentials", "true");
        header("Access-Control-Allow-Methods", "*");
        header("Access-Control-Allow-Headers", "Content-Type,Access-Token");
        header("Access-Control-Expose-Headers", "*");
        header("Content-Type: text/html; charset=utf-8"); 
    }
	public function getVersion(){
		$request=Request::instance();
	    $data=$request->param();
		$v=['version'=>'1.0.0','indata'=>$data];
		session('gh',"22212222");
		return json_encode($v);
	}
	public function logincheck()
	{
		$request=Request::instance();
	    $u=$request->param("username");
	    $p=$request->param("password");
	    $db=new mydb();
	    $t=$db->checkLoginInfo($u,md5($p));
	    if ($t[0]['cnt']>0) {
	    	session('gh',$u);
	    	return json_encode(['result'=>1,'info'=>'login ok']);
	    }else{
	    	return json_encode(['result'=>0,'info'=>'login error']);
	    }
	}
	public function changpassword()
	{
		$request=Request::instance();
	    $p0=md5($request->param("password0"));
	    $p1=$request->param("password1");
	    $p2=$request->param("password2");
	    if ($p1!=$p2) {
	    	return json_encode(['result'=>0,'info'=>'两次输入密码不一致！']);
	    }
	    if (strlen($p1)<6) {
	    	return json_encode(['result'=>0,'info'=>'密码长度不能小于6！']);
	    }

	    $db=new mydb();
	    $t=$db->checkLoginInfo(session("gh"),$p0);
	    if ($t[0]['cnt']==0) {
	    	return json_encode(['result'=>0,'info'=>'原密码不正确']);
	    }
	    $db->changepsd(session("gh"),md5($p1));
		return json_encode(['result'=>1,'info'=>'密码修改成功']);
	}
	public function logout()
	{
		session('gh',null);
		return json_encode(['result'=>1,'info'=>'logout ok']);
	}



}







